package com.hjy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hjy.entity.User;
import com.hjy.service.UserService;
import com.hjy.service.impl.UserServiceImpl;

public class RegisterByEmailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private UserService userService = new UserServiceImpl();
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String loginName = request.getParameter("login_name");
		String password = request.getParameter("password");
		
		String email = request.getParameter("email");
		
		User user = new User();
		user.setLoginName(loginName);
		user.setPassword(password);
		user.setStatus(0); //未激活状态
		user.setUsername(loginName);
		user.setEmail(email);
		if(userService.registerByEmail(user)){
			response.getWriter().print("注册成功！用户名："+loginName+", 密码："+password+",请登录邮箱进行验证(5分钟有效)："+email);
		} else {
			response.getWriter().print("注册失败！");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
